import { NBreadcrumbItem, type BreadcrumbItemProps } from "naive-ui";
import type { HTMLAttributes } from "vue";
import type { BaseComponentType } from "../types";
import { getSlotsDom } from "../utils";
export type BreadcrumbItemFactoryConstructorType = {
  props?: BreadcrumbItemProps;
  attrs?: HTMLAttributes;
  defaultSlot?: BaseComponentType;
  separatorSlot?: BaseComponentType;
};
export class BreadcrumbItemFactory {
  private props: BreadcrumbItemProps = {};
  private attrs: HTMLAttributes = {};
  private defaultSlot: BaseComponentType = null;
  private separatorSlot: BaseComponentType = null;
  constructor(data?: BreadcrumbItemFactoryConstructorType) {
    if (data?.props) this.setProps(data.props);
    if (data?.attrs) this.setAttrs(data.attrs);
    if (data?.defaultSlot) this.setDefault(data.defaultSlot);
    if (data?.separatorSlot) this.setSeparator(data.separatorSlot);
  }
  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this;
  }

  setProps(props: BreadcrumbItemProps) {
    this.props = props;
    return this;
  }

  setDefault(component: BaseComponentType) {
    this.defaultSlot = component;
    return this;
  }

  setSeparator(component: BaseComponentType) {
    this.separatorSlot = component;
    return this;
  }

  create() {
    return (
      <NBreadcrumbItem {...this.props} {...this.attrs}>
        {{
          default:
            this.defaultSlot != null
              ? () => getSlotsDom(this.defaultSlot)
              : null,
          separator:
            this.separatorSlot != null
              ? () => getSlotsDom(this.separatorSlot)
              : null,
        }}
      </NBreadcrumbItem>
    );
  }
}
